package com.jincp.filepicker.ui.image;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.jincp.common.model.ToolBarOptions;
import com.jincp.filepicker.R;
import com.jincp.filepicker.base.FileBaseActivity;
import com.jincp.filepicker.bean.ImageFile;
import com.jincp.image.load.ImageLoader;

import uk.co.senab.photoview.PhotoView;

/**
 * =========================================================
 * @ProjectName:
 * @ClassName: ImagePreviewActivity
 * @Description:
 * @Author: jincp
 * @CreateDate: 2019/3/23 15:49
 * =========================================================
 */
public class ImagePreviewActivity extends FileBaseActivity  {


    public static final String IMAGE_FILE = "IMAGE_FILE";

    private ImageFile imageFile;

    @Override
    protected void configIntentValue() {
        Intent intent = getIntent();
        if (intent != null){
            imageFile = intent.getParcelableExtra(IMAGE_FILE);
        }
    }

    @Override
    protected int getContentLayout() {
        return R.layout.activity_image_preview;
    }

    @Override
    protected void initViews() {
        setCustomToolBar((Toolbar) findViewById(R.id.toolbar), new ToolBarOptions());

        Button btnCompleted = findViewById(R.id.btn_complete);
        btnCompleted.setEnabled(true);
        btnCompleted.setVisibility(View.VISIBLE);
        if (ImagePickerManager.getInstance().getSelectFileCount() > 0) {
            btnCompleted.setText(getString(R.string.selected_complete, ImagePickerManager.getInstance().getSelectFileCount(), ImagePickerManager.getInstance().getMaxSelectedLimit()));
        } else {
            btnCompleted.setText(R.string.complete);
        }
        btnCompleted.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ImagePickerManager.getInstance().addSelectedFile(imageFile);
                finish();
            }
        });

        PhotoView photoView = (PhotoView) findViewById(R.id.photoView);
        photoView.setEnabled(true);
        photoView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

        ImageLoader.getInstance().displayImage(imageFile.getPath(), photoView);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
    }
}
